/**
 * 全局类型定义
 */

// API响应类型
export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

// 用户相关类型
export interface User {
  id: string;
  username: string;
  nickname: string;
  email?: string;
  avatar?: string | null;
  status: number;
  createdAt?: string;
  updatedAt?: string;
}

// 群组相关类型
export interface Group {
  id: string;
  name: string;
  description?: string;
  avatar?: string;
  ownerId: string;
  createdAt: string;
  updatedAt: string;
}

// 登录请求类型
export interface LoginRequest {
  account: string;
  password: string;
}

// 注册请求类型
export interface RegisterRequest {
  username: string;
  password: string;
  email: string;
  nickname: string;
}

// 登录响应类型
export interface LoginResponse {
  token: string;
  tokenType: string | null;
  userId: string;
  username: string;
  nickname: string;
  avatar: string | null;
  email?: string;
}

// 文件上传响应类型
export interface FileUploadResponse {
  filename: string;
  url: string;
  size: number;
  contentType: string;
}

// 用户搜索结果类型
export interface UserSearchResult {
  id: string;
  email: string;
  username: string;
  nickname: string;
  avatar: string;
  isFriend: boolean;
  friendStatus: number;
}

// 添加好友请求类型
export interface AddFriendRequest {
  friendId: string;
  remark?: string;
}

// 分页响应类型
export interface Page<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

/**
 * WebSocket消息类型枚举
 */
export enum WebSocketMessageType {
  CONNECT = "CONNECT", // 连接消息
  DISCONNECT = "DISCONNECT", // 断开连接
  PRIVATE_MSG = "PRIVATE_MSG", // 私聊消息
  GROUP_MSG = "GROUP_MSG", // 群聊消息
  FRIEND_REQ = "FRIEND_REQ", // 好友请求
  FRIEND_RES = "FRIEND_RES", // 好友响应
  HEARTBEAT = "HEARTBEAT", // 心跳消息
  ERROR = "ERROR", // 错误消息
}

/**
 * WebSocket消息接口
 */
export interface WebSocketMessage<T = any> {
  type: WebSocketMessageType; // 消息类型
  senderId?: string; // 发送者ID
  receiverId?: string; // 接收者ID
  data: T; // 消息数据
  timestamp: number; // 时间戳
}

/**
 * 好友请求消息数据接口
 */
export interface FriendRequestData {
  id: string;
  userId: string;
  username: string;
  nickname: string;
  avatar: string;
  remark: string;
  status: number;
  createdAt: string;
}

/**
 * 会话实体接口
 */
export interface ChatSession {
  id: string;
  userId: string;
  targetId: string;
  type: number; //0:私聊 1:群聊
  lastMessage?: string;
  unreadCount: number;
  isTop: boolean;
  status: number; //0:正常 1:已删除
  lastMessageTime?: string;
  createdAt: string;
  updatedAt: string;
}

/**
 * 会话响应接口
 */
export interface ChatSessionResponse {
  id: string;
  targetId: string;
  targetName: string;
  targetAvatar: string;
  lastMessage: string;
  lastMessageTime: string;
  unreadCount: number;
  type: ChatSessionType;
  isTop: boolean;
}

/**
 * 会话类型枚举
 */
export enum ChatSessionType {
  PRIVATE = 0,
  GROUP = 1,
}

/**
 * 私聊消息实体接口
 */
export interface PrivateMessage {
  id: string; // 后端为Long类型，前端使用string接收
  senderId: string; // 后端为Long类型，前端使用string接收
  receiverId: string; // 后端为Long类型，前端使用string接收
  content: string; //消息内容
  type: number; //0:文本 1:图片 2:语音 3:视频 4:文件
  status: number; //0:未读 1:已读 2:已删除
  createdAt: string; // 后端为LocalDateTime类型，前端使用string接收
  updatedAt: string; // 后端为LocalDateTime类型，前端使用string接收
}

/**
 * 消息类型枚举
 */
export enum MessageType {
  TEXT = 0, // 文本
  IMAGE = 1, // 图片
  VOICE = 2, // 语音
  VIDEO = 3, // 视频
  FILE = 4, // 文件
}

/**
 * 消息状态枚举
 */
export enum MessageStatus {
  UNREAD = 0, // 未读
  READ = 1, // 已读
  DELETED = 2, // 已删除
}
